#include<iostream>
using namespace std;
template<typename T>
void find(T* a,int n) {
	T s1 = a[0];
	int m1 = 0;
	for (int i = 0; i < n; i++) {
		T s2 = a[i];
		int m2 = 0;
		for (int j = 0; j < n; j++) {
			if (a[i] == a[j]) {
				m2++;
			}
		}
		if (m2 > m1) {
			m1 = m2;
			s1 = s2;
		}
	}
	cout << s1 << ' ' << m1;
}
int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		char c;
		int n;
		cin >> c >> n;
		if (c == 'I') {
			int* a = new int[n];
			for (int j = 0; j < n; j++) {
				cin >> a[j];
			}
			find(a, n);
		}
		else if (c == 'C') {
			char* a = new char[n];
			for (int j = 0; j < n; j++) {
				cin >> a[j];
			}
			find(a, n);
		}
		else {
			string* a = new string[n];
			for (int j = 0; j < n; j++) {
				cin >> a[j];
			}
			find(a, n);
		}
		if (i < t - 1) {
			cout << endl;
		}
	}
	return 0;
}